#include<iostream>
#include<algorithm>

using namespace std;

const int N=1e6+10;

struct H{
	int a,b;
}h[N];

int n,m;


bool cmp(H a,H b){
	if(a.b==b.b) return a.a<b.a;
	return a.b<b.b;
}


int k(int n)
{
	int sum=0;
	while(n){
		sum+=n%10;
		n/=10;
	}
	return sum;
}


int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) h[i].a=i,h[i].b=k(i);
	
	sort(h+1,h+n+1,cmp);
	
	printf("%d",h[m].a);
	
	return 0;
} 
